package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.DustVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by lzh on 2018/3/17.
 */

public class DustAdapter extends LemonRcvAdapter<DustVo> {
    private RecyclerTClickListener<DustVo> mListener;

    public DustAdapter(@Nullable List<DustVo> data, RecyclerTClickListener<DustVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new DustItem();
    }

    public class DustItem implements AdapterItem<DustVo> {
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        @Bind(R.id.tv_space_name)
        TextView tvSpaceName;
        @Bind(R.id.tv_dust_people_number)
        TextView tvDustPeopleNumber;

        @Bind(R.id.tv_isHasCleaner)
        TextView tvIsHasCleaner;
        @Bind(R.id.tv_isRelateBomb)
        TextView tvIsRelateBomb;
        @Bind(R.id.tv_isDamage)
        TextView tvIsDamage;
        @Bind(R.id.tv_dust_single_wrokers)
        TextView tvDustSingleWrokers;
        private DustVo data;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_dust_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(DustVo dustVo, int position) {
            data = dustVo;
            pos = position;
            tvSpaceName.setText(dustVo.getType());
            tvDustPeopleNumber.setText(CommonUtil.avoidNullString(dustVo.getWorkers()));
            tvDustSingleWrokers.setText(CommonUtil.avoidNullString(dustVo.getShiftWorkers()));
            tvIsHasCleaner.setText(CommonUtil.avoidNullString(dustVo.getDuster()));
            tvIsRelateBomb.setText(CommonUtil.avoidNullString(dustVo.getIsBomb()));
            tvIsDamage.setText(CommonUtil.avoidNullString(dustVo.getIsOccupational()));
        }
    }
}
